In [2]:
import numpy as np
In [3]:
#Define constants - current, permittivity of free space, permeability of free space, wire radius a.
I = 4
e_0 = 8.85 * 10**(-12)
u_0 = 1.26 * 10**(-6)
a = 0.005
In [4]:
#Define a function for the magnitude of the electric field and magnetic field as a function of time and position.
#Here the electric field does not depend on position, and the magnetic field does not depend on time.
def E(t):
return (I * t) / (np.pi * a**2 * e_0)
def B(s):
return (u_0 * I * s) / (2 * np.pi * a**2)
In [5]:
#Import 3-dimensional plotting package.
from mpl_toolkits.mplot3d import axes3d
In [11]:
#Make a three-dimensional plot.
fig = plt.figure(figsize = (8, 8))
ax = fig.gca(projection = '3d')
#Define the width of the gap. It is "much smaller than a". At this point, I am guessing about the magnitude appropriate for this approximation.
w = a/100
#Make a grid of points where vectors of the vector field are placed.
#Only want vectors within the cylindrical gap region centered at the origin.
s_lim = a
phi_lim = 2 * np.pi
z_lim = w/2
S, PHI, Z = np.meshgrid(np.arange(0, s_lim, s_lim/3),
np.arange(0, phi_lim, phi_lim/8),
np.arange(-z_lim, z_lim, z_lim/3))
#Choose a time (in seconds) to plot the electric and magnetic fields, since the electric field is changing with time.
t = 0.5
X = S * np.cos(PHI)
Y = S * np.sin(PHI)
Z = Z
U_electric = 0
V_electric = 0
W_electric = E(t)/(0.5*10**21)
U_magnetic = B(S) * (-np.sin(PHI)) * 10
V_magnetic = B(S) * (np.cos(PHI)) * 10
W_magnetic = 0
#Plot the vector field - electric field.
ax.quiver(X, Y, Z, U_electric, V_electric, W_electric, color = 'orange', arrow_length_ratio = 0.3, linewidths = 1, length = 1, label = "Electric Field")
#Plot the vector field - magnetic field.
ax.quiver(X, Y, Z, U_magnetic, V_magnetic, W_magnetic, color = 'b', arrow_length_ratio = 0.0005, linewidths = 1, length = 1, label = "Magnetic Field")
ax.set_xlim3d(-0.005, 0.005)
ax.set_ylim3d(-0.005, 0.005)
ax.set_zlim3d(-2*z_lim, 2*z_lim)
#Adjust the viewing angle of the plot.
ax.view_init(elev = 20, azim = 300)
#Label the plot.
ax.set_xlabel('x (meters)')
ax.set_ylabel('y (meters)')
ax.set_zlabel('z (meters)')
ax.legend(loc = 'lower left')
ax.set_title('Electric and Magnetic Field Directions Between Wire Gap', fontsize = 16)
plt.show()
In [13]:
#Plot only the ELECTRIC FIELD.
#Make a three-dimensional plot.
fig = plt.figure(figsize = (8, 8))
ax = fig.gca(projection = '3d')
#Define the width of the gap. It is "much smaller than a". At this point, I am guessing about the magnitude appropriate for this approximation.
w = a/100
#Make a grid of points where vectors of the vector field are placed.
#Only want vectors within the cylindrical gap region centered at the origin.
s_lim = a
phi_lim = 2 * np.pi
z_lim = w/2
S, PHI, Z = np.meshgrid(np.arange(0, s_lim, s_lim/3),
np.arange(0, phi_lim, phi_lim/8),
np.arange(-z_lim, z_lim, z_lim/3))
#Choose a time (in seconds) to plot the electric and magnetic fields, since the electric field is changing with time.
t = 0.5
X = S * np.cos(PHI)
Y = S * np.sin(PHI)
Z = Z
U_electric = 0
V_electric = 0
W_electric = E(t)/(0.5*10**21)
#Plot the vector field - electric field.
ax.quiver(X, Y, Z, U_electric, V_electric, W_electric, color = 'orange', arrow_length_ratio = 0.3, linewidths = 1, length = 1, label = "Electric Field")
ax.set_xlim3d(-0.005, 0.005)
ax.set_ylim3d(-0.005, 0.005)
ax.set_zlim3d(-2*z_lim, 2*z_lim)
#Adjust the viewing angle of the plot.
ax.view_init(elev = 20, azim = 300)
#Label the plot.
ax.set_xlabel('x (meters)')
ax.set_ylabel('y (meters)')
ax.set_zlabel('z (meters)')
ax.legend(loc = 'lower left')
ax.set_title('Electric Field Direction Between Wire Gap', fontsize = 16)
plt.show()
In [12]:
#Plot only the MAGNETIC FIELD.
#Make a three-dimensional plot.
fig = plt.figure(figsize = (8, 8))
ax = fig.gca(projection = '3d')
#Define the width of the gap. It is "much smaller than a". At this point, I am guessing about the magnitude appropriate for this approximation.
w = a/100
#Make a grid of points where vectors of the vector field are placed.
#Only want vectors within the cylindrical gap region centered at the origin.
s_lim = a
phi_lim = 2 * np.pi
z_lim = w/2
S, PHI, Z = np.meshgrid(np.arange(0, s_lim, s_lim/5),
np.arange(0, phi_lim, phi_lim/8),
np.arange(-z_lim, z_lim, z_lim))
#Choose a time (in seconds) to plot the electric and magnetic fields, since the electric field is changing with time.
t = 0.5
X = S * np.cos(PHI)
Y = S * np.sin(PHI)
Z = Z
U_magnetic = B(S) * (-np.sin(PHI)) * 10
V_magnetic = B(S) * (np.cos(PHI)) * 10
W_magnetic = 0
#Plot the vector field - magnetic field.
ax.quiver(X, Y, Z, U_magnetic, V_magnetic, W_magnetic, color = 'b', arrow_length_ratio = 0.0005, linewidths = 1, length = 1, label = "Magnetic Field")
ax.set_xlim3d(-0.005, 0.005)
ax.set_ylim3d(-0.005, 0.005)
ax.set_zlim3d(-2*z_lim, 2*z_lim)
#Adjust the viewing angle of the plot.
ax.view_init(elev = 20, azim = 300)
#Label the plot.
ax.set_xlabel('x (meters)')
ax.set_ylabel('y (meters)')
ax.set_zlabel('z (meters)')
ax.legend(loc = 'lower left')
ax.set_title('Magnetic Field Direction Between Wire Gap', fontsize = 16)
plt.show()
In [34]:
#Plot the Poynting vector.
fig = plt.figure(figsize = (8, 8))
ax = fig.gca(projection = '3d')
#Define the width of the gap. It is "much smaller than a". At this point, I am guessing about the magnitude appropriate for this approximation.
w = a/100
#Make a grid of points where vectors of the vector field are placed.
#Only want vectors within the cylindrical gap region centered at the origin.
s_lim = a
phi_lim = 2 * np.pi
z_lim = w/2
S, PHI, Z = np.meshgrid(np.arange(0, s_lim, s_lim/3),
np.arange(0, phi_lim, phi_lim/8),
np.arange(-z_lim, z_lim, z_lim/3))
#Choose a time (in seconds) to plot the electric and magnetic fields, since the electric field is changing with time.
t = 0.5
#Define the Poynting vector as a function of time and position.
c = 2.99792 * 10**8
def Poynting(t, s):
return - (u_0 * I**2 * c**2 * t * s) / (2 * np.pi**2 * a**4)
X = S * np.cos(PHI)
Y = S * np.sin(PHI)
Z = Z
U_Poynting = Poynting(t, S) * (np.cos(PHI)) / 10**20
V_Poynting = Poynting(t, S) * (np.sin(PHI)) / 10**20
W_Poynting = 0
#Plot the vector field - magnetic field.
ax.quiver(X, Y, Z, U_Poynting, V_Poynting, W_Poynting, color = 'b', arrow_length_ratio = 0.002, linewidths = 1, length = 1, label = 'Poynting vector')
ax.set_xlim3d(-0.005, 0.005)
ax.set_ylim3d(-0.005, 0.005)
ax.set_zlim3d(-2*z_lim, 2*z_lim)
#Adjust the viewing angle of the plot.
ax.view_init(elev = 20, azim = 300)
#Label the plot.
ax.set_xlabel('x (meters)')
ax.set_ylabel('y (meters)')
ax.set_zlabel('z (meters)')
ax.legend(loc = 'lower left')
ax.set_title('Poynting Vector Direction Between Wire Gap', fontsize = 16)
plt.show()